package com.ruan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruan.entity.Discuss;
import com.ruan.entity.R;
import com.ruan.service.DiscussService;
import com.ruan.mapper.DiscussMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 59499
* @description 针对表【tb_discuss】的数据库操作Service实现
* @createDate 2023-09-20 15:00:05
*/
@Service
public class DiscussServiceImpl extends ServiceImpl<DiscussMapper, Discuss>
    implements DiscussService{

    @Autowired
    private DiscussMapper discussMapper;

    @Override
    public R<List<Discuss>> getDiscussByKnowledgeId(Integer knowledgeId) {
        QueryWrapper<Discuss> wrapper = new QueryWrapper<>();
        wrapper.select("discuss_id","own_name","content","create_time");
        wrapper.eq("knowledge_id",knowledgeId);
        List<Discuss> discussList = discussMapper.selectList(wrapper);
        return R.ok("查询成功",discussList);
    }

    @Override
    public R<Void> addDiscuss(Discuss discuss) {
        int row = discussMapper.insert(discuss);
        if (row != 1){
            return R.error("添加失败");
        }
        return R.ok("添加成功");
    }
}




